﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Dimok.Web.UI;
using AjaxMasterExtentions;
public partial class Manager_AjaxMaster : System.Web.UI.MasterPage {
	protected override void OnPreRender(EventArgs e) {
		this.TraceMe("Start");
		base.OnPreRender(e);
		var ULs = Find.ChildrenByType(this, typeof(HtmlGenericControl)).Cast<HtmlGenericControl>().Where(c => new[] { "ul", "li" }.Contains(c.TagName)).ToArray();
		JS.SetProfileIDs(ULs);
		Control rge = Find.ChildByType(Page, typeof(RadGridExtender));
		Profiler profiler = rge == null ? this.GetProfiler() : this.GetProfiler(rge);
		string ReportName = profiler.Report_FindName();
		if (profiler.Docks("").Count > 0)
			foreach (var row in profiler.Docks(ReportName)) {
				Control ul = Find.ControlByID(Page, row.Key);
				foreach (var child in row.Value.Children.Split('\n')) {
					if (child == "") continue;
					Control li = Find.ControlByID(Page, child);
					if (li != null) ul.Controls.Add(li);
				}
			}
		Page.PreRenderComplete += new EventHandler(Page_PreRenderComplete);
		this.TraceMe("End");
	}

	void Page_PreRenderComplete(object sender, EventArgs e) {
		string wsProfilerPath = "/Manager/webservices/profiler.asmx/SaveFontSize";
		Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "FONTCSS", @"
var pageType = '" + Page.GetType().Name + @"';
var wsProfilerPath = '" + wsProfilerPath + @"';
			", true);
		this.RegisterCSS(wsProfilerPath + "?pageType=" + Page.GetType().Name + "&size=");
		this.RegisterCSS("/CSS/Office2007.css");
	}
}
